#include "zkproxy.h"

IMPL_LOGGER(zkproxy,logger);

zkproxy::zkproxy()
{
	m_zkhandle = NULL;
}

zkproxy::zkproxy(const std::string &host,const int &timeoutms):m_host(host),m_timeoutms(timeoutms),m_zkhandle(NULL)
{
	LOG4CPLUS_DEBUG(logger,"host info: "<<m_host<<"recv time out: "<<m_timeoutms);
}

zkproxy::~zkproxy()
{
	if(m_zkhandle)
	{
		int errono = ZOK; 
		
		if((errono=zookeeper_close(m_zkhandle)) != ZOK)
		{
			LOG4CPLUS_ERROR(logger,"close zkhandle failed errono: "<<errono)
		}
		
		m_zkhandle = NULL;
	}
}

bool zkproxy::zk_init()
{
	m_zkhandle = zookeeper_init(m_host.c_str(),watch_callback,m_timeoutms,0,this,0);

	if(m_zkhandle == NULL)
	{
		LOG4CPLUS_DEBUG(logger,"init zk hanle failed: "<<strerror());
	}

	
}

void zkproxy::watch_callback(zhandle_t *zkhandle,int type,int state,const char *path,void *watchercrtx)
{

}
